package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysInOut;
import com.ruoyi.system.service.ISysInOutService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出入库台账Controller
 *
 * @author ruoyi
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/system/out")
public class SysInOutController extends BaseController
{
    @Autowired
    private ISysInOutService sysInOutService;

    /**
     * 查询出入库台账列表
     */
    @PreAuthorize("@ss.hasPermi('system:out:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysInOut sysInOut)
    {
        startPage();
        List<SysInOut> list = sysInOutService.selectSysInOutList(sysInOut);
        return getDataTable(list);
    }

    /**
     * 导出出入库台账列表
     */
    @PreAuthorize("@ss.hasPermi('system:out:export')")
    @Log(title = "出入库台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysInOut sysInOut)
    {
        List<SysInOut> list = sysInOutService.selectSysInOutList(sysInOut);
        ExcelUtil<SysInOut> util = new ExcelUtil<SysInOut>(SysInOut.class);
        util.exportExcel(response, list, "出入库台账数据");
    }

    /**
     * 获取出入库台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:out:query')")
    @GetMapping(value = "/{outId}")
    public AjaxResult getInfo(@PathVariable("outId") Long outId)
    {
        return success(sysInOutService.selectSysInOutByOutId(outId));
    }

    /**
     * 新增出入库台账
     */
    @PreAuthorize("@ss.hasPermi('system:out:add')")
    @Log(title = "出入库台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysInOut sysInOut)
    {
        sysInOut.setCreateBy(getUsername());
        return toAjax(sysInOutService.insertSysInOut(sysInOut));
    }

    /**
     * 修改出入库台账
     */
    @PreAuthorize("@ss.hasPermi('system:out:edit')")
    @Log(title = "出入库台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysInOut sysInOut)
    {
        sysInOut.setUpdateBy(getUsername());
        return toAjax(sysInOutService.updateSysInOut(sysInOut));
    }

    /**
     * 删除出入库台账
     */
    @PreAuthorize("@ss.hasPermi('system:out:remove')")
    @Log(title = "出入库台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{outIds}")
    public AjaxResult remove(@PathVariable Long[] outIds)
    {
        return toAjax(sysInOutService.deleteSysInOutByOutIds(outIds));
    }
}
